home *** CD-ROM | disk | FTP | other *** search
/ The Arsenal Files 8 / The Arsenal Files Collection #8 (Arsenal Computer) (1996).ISO / g_quake / godelqc5.zip / TRIGGERS.QC < prev    next >
Text File  |  1996-09-18  |  16KB  |  664 lines

  1.  
  2. entity stemp, otemp, s, old;
  3.  
  4.  
  5. void() trigger_reactivate =
  6. {
  7.     self.solid = SOLID_TRIGGER;
  8. };
  9.  
  10. //=============================================================================
  11.  
  12. float   SPAWNFLAG_NOMESSAGE = 1;
  13. float   SPAWNFLAG_NOTOUCH = 1;
  14.  
  15. // the wait time has passed, so set back up for another activation
  16. void() multi_wait =
  17. {
  18.     if (self.max_health)
  19.     {
  20.         self.health = self.max_health;
  21.         self.takedamage = DAMAGE_YES;
  22.         self.solid = SOLID_BBOX;
  23.     }
  24. };
  25.  
  26.  
  27. // the trigger was just touched/killed/used
  28. // self.enemy should be set to the activator so it can be held through a delay
  29. // so wait for the delay time before firing
  30. void() multi_trigger =
  31. {
  32.     if (self.nextthink > time)
  33.     {
  34.         return;         // allready been triggered
  35.     }
  36.  
  37.     if (self.classname == "trigger_secret")
  38.     {
  39.         if (self.enemy.classname != "player")
  40.             return;
  41.         found_secrets = found_secrets + 1;
  42.         WriteByte (MSG_ALL, SVC_FOUNDSECRET);
  43.     }
  44.  
  45.     if (self.noise)
  46.         sound (self, CHAN_VOICE, self.noise, 1, ATTN_NORM);
  47.  
  48. // don't trigger again until reset
  49.     self.takedamage = DAMAGE_NO;
  50.  
  51.     activator = self.enemy;
  52.     
  53.     SUB_UseTargets();
  54.  
  55.     if (self.wait > 0)      
  56.     {
  57.         self.think = multi_wait;
  58.         self.nextthink = time + self.wait;
  59.     }
  60.     else
  61.     {       // we can't just remove (self) here, because this is a touch function
  62.         // called wheil C code is looping through area links...
  63.         self.touch = SUB_Null;
  64.         self.nextthink = time + 0.1;
  65.         self.think = SUB_Remove;
  66.     }
  67. };
  68.  
  69. void() multi_killed =
  70. {
  71.     self.enemy = damage_attacker;
  72.     multi_trigger();
  73. };
  74.  
  75. void() multi_use =
  76. {
  77.     self.enemy = activator;
  78.     multi_trigger();
  79. };
  80.  
  81. void() multi_touch =
  82. {
  83.     if (other.classname != "player")
  84.         return;
  85.     
  86. // if the trigger has an angles field, check player's facing direction
  87.     if (self.movedir != '0 0 0')
  88.     {
  89.         makevectors (other.angles);
  90.         if (v_forward * self.movedir < 0)
  91.             return;         // not facing the right way
  92.     }
  93.     
  94.     self.enemy = other;
  95.     multi_trigger ();
  96. };
  97.  
  98. /*QUAKED trigger_multiple (.5 .5 .5) ? notouch
  99. Variable sized repeatable trigger.  Must be targeted at one or more entities.  If "health" is set, the trigger must be killed to activate each time.
  100. If "delay" is set, the trigger waits some time after activating before firing.
  101. "wait" : Seconds between triggerings. (.2 default)
  102. If notouch is set, the trigger is only fired by other entities, not by touching.
  103. NOTOUCH has been obsoleted by trigger_relay!
  104. sounds
  105. 1)      secret
  106. 2)      beep beep
  107. 3)      large switch
  108. 4)
  109. set "message" to text string
  110. */
  111. void() trigger_multiple =
  112. {
  113.     if (self.sounds == 1)
  114.     {
  115.         precache_sound ("misc/secret.wav");
  116.         self.noise = "misc/secret.wav";
  117.     }
  118.     else if (self.sounds == 2)
  119.     {
  120.         precache_sound ("misc/talk.wav");
  121.         self.noise = "misc/talk.wav";
  122.     }
  123.     else if (self.sounds == 3)
  124.     {
  125.         precache_sound ("misc/trigger1.wav");
  126.         self.noise = "misc/trigger1.wav";
  127.     }
  128.     
  129.     if (!self.wait)
  130.         self.wait = 0.2;
  131.     self.use = multi_use;
  132.  
  133.     InitTrigger ();
  134.  
  135.     if (self.health)
  136.     {
  137.         if (self.spawnflags & SPAWNFLAG_NOTOUCH)
  138.             objerror ("health and notouch don't make sense\n");
  139.         self.max_health = self.health;
  140.         self.th_die = multi_killed;
  141.         self.takedamage = DAMAGE_YES;
  142.         self.solid = SOLID_BBOX;
  143.         setorigin (self, self.origin);  // make sure it links into the world
  144.     }
  145.     else
  146.     {
  147.         if ( !(self.spawnflags & SPAWNFLAG_NOTOUCH) )
  148.         {
  149.             self.touch = multi_touch;
  150.         }
  151.     }
  152. };
  153.  
  154.  
  155. /*QUAKED trigger_once (.5 .5 .5) ? notouch
  156. Variable sized trigger. Triggers once, then removes itself.  You must set the key "target" to the name of another object in the level that has a matching
  157. "targetname".  If "health" is set, the trigger must be killed to activate.
  158. If notouch is set, the trigger is only fired by other entities, not by touching.
  159. if "killtarget" is set, any objects that have a matching "target" will be removed when the trigger is fired.
  160. if "angle" is set, the trigger will only fire when someone is facing the direction of the angle.  Use "360" for an angle of 0.
  161. sounds
  162. 1)      secret
  163. 2)      beep beep
  164. 3)      large switch
  165. 4)
  166. set "message" to text string
  167. */
  168. void() trigger_once =
  169. {
  170.     self.wait = -1;
  171.     trigger_multiple();
  172. };
  173.  
  174. //=============================================================================
  175.  
  176. /*QUAKED trigger_relay (.5 .5 .5) (-8 -8 -8) (8 8 8)
  177. This fixed size trigger cannot be touched, it can only be fired by other events.  It can contain killtargets, targets, delays, and messages.
  178. */
  179. void() trigger_relay =
  180. {
  181.     self.use = SUB_UseTargets;
  182. };
  183.  
  184.  
  185. //=============================================================================
  186.  
  187. /*QUAKED trigger_secret (.5 .5 .5) ?
  188. secret counter trigger
  189. sounds
  190. 1)      secret
  191. 2)      beep beep
  192. 3)
  193. 4)
  194. set "message" to text string
  195. */
  196. void() trigger_secret =
  197. {
  198.     total_secrets = total_secrets + 1;
  199.     self.wait = -1;
  200.     if (!self.message)
  201.         self.message = "You found a secret area!";
  202.     if (!self.sounds)
  203.         self.sounds = 1;
  204.     
  205.     if (self.sounds == 1)
  206.     {
  207.         precache_sound ("misc/secret.wav");
  208.         self.noise = "misc/secret.wav";
  209.     }
  210.     else if (self.sounds == 2)
  211.     {
  212.         precache_sound ("misc/talk.wav");
  213.         self.noise = "misc/talk.wav";
  214.     }
  215.  
  216.     trigger_multiple ();
  217. };
  218.  
  219. //=============================================================================
  220.  
  221.  
  222. void() counter_use =
  223. {
  224.     local string junk;
  225.  
  226.     self.count = self.count - 1;
  227.     if (self.count < 0)
  228.         return;
  229.     
  230.     if (self.count != 0)
  231.     {
  232.         if (activator.classname == "player"
  233.         && (self.spawnflags & SPAWNFLAG_NOMESSAGE) == 0)
  234.         {
  235.             if (self.count >= 4)
  236.                 centerprint (activator, "There are more to go...");
  237.             else if (self.count == 3)
  238.                 centerprint (activator, "Only 3 more to go...");
  239.             else if (self.count == 2)
  240.                 centerprint (activator, "Only 2 more to go...");
  241.             else
  242.                 centerprint (activator, "Only 1 more to go...");
  243.         }
  244.         return;
  245.     }
  246.     
  247.     if (activator.classname == "player"
  248.     && (self.spawnflags & SPAWNFLAG_NOMESSAGE) == 0)
  249.         centerprint(activator, "Sequence completed!");
  250.     self.enemy = activator;
  251.     multi_trigger ();
  252. };
  253.  
  254. /*QUAKED trigger_counter (.5 .5 .5) ? nomessage
  255. Acts as an intermediary for an action that takes multiple inputs.
  256.  
  257. If nomessage is not set, t will print "1 more.. " etc when triggered and "sequence complete" when finished.
  258.  
  259. After the counter has been triggered "count" times (default 2), it will fire all of it's targets and remove itself.
  260. */
  261. void() trigger_counter =
  262. {
  263.     self.wait = -1;
  264.     if (!self.count)
  265.         self.count = 2;
  266.  
  267.     self.use = counter_use;
  268. };
  269.  
  270.  
  271. /*
  272. ==============================================================================
  273.  
  274. TELEPORT TRIGGERS
  275.  
  276. ==============================================================================
  277. */
  278.  
  279. float   PLAYER_ONLY     = 1;
  280. float   SILENT = 2;
  281.  
  282. void() play_teleport =
  283. {
  284.     local   float v;
  285.     local   string tmpstr;
  286.  
  287.     v = random() * 5;
  288.     if (v < 1)
  289.         tmpstr = "misc/r_tele1.wav";
  290.     else if (v < 2)
  291.         tmpstr = "misc/r_tele2.wav";
  292.     else if (v < 3)
  293.         tmpstr = "misc/r_tele3.wav";
  294.     else if (v < 4)
  295.         tmpstr = "misc/r_tele4.wav";
  296.     else
  297.         tmpstr = "misc/r_tele5.wav";
  298.  
  299.     sound (self, CHAN_VOICE, tmpstr, 1, ATTN_NORM);
  300.     remove (self);
  301. };
  302.  
  303. void(vector org) spawn_tfog =
  304. {
  305.     s = spawn ();
  306.     s.origin = org;
  307.     s.nextthink = time + 0.2;
  308.     s.think = play_teleport;
  309.  
  310.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  311.     WriteByte (MSG_BROADCAST, TE_TELEPORT);
  312.     WriteCoord (MSG_BROADCAST, org_x);
  313.     WriteCoord (MSG_BROADCAST, org_y);
  314.     WriteCoord (MSG_BROADCAST, org_z);
  315. };
  316.  
  317.  
  318. void() tdeath_touch =
  319. {
  320.     if (other == self.owner)
  321.         return;
  322.  
  323. // frag anyone who teleports in on top of an invincible player
  324.     if (other.classname == "player")
  325.     {
  326.         if (other.invincible_finished > time)
  327.             self.classname = "teledeath2";
  328.         if (self.owner.classname != "player")
  329.         {       // other monsters explode themselves
  330.             T_Damage (self.owner, self, self, 50000);
  331.             return;
  332.         }
  333.         
  334.     }
  335.  
  336.     if (other.health)
  337.     {
  338.         T_Damage (other, self, self.owner, 50000);
  339.     }
  340. };
  341.  
  342.  
  343. void(vector org, entity death_owner) spawn_tdeath =
  344. {
  345. local entity    death;
  346.  
  347.     death = spawn();
  348.     death.classname = "teledeath";
  349.     death.movetype = MOVETYPE_NONE;
  350.     death.solid = SOLID_TRIGGER;
  351.     death.angles = '0 0 0';
  352.     setsize (death, death_owner.mins - '1 1 1', death_owner.maxs + '1 1 1');
  353.     setorigin (death, org);
  354.     death.touch = tdeath_touch;
  355.     death.nextthink = time + 0.2;
  356.     death.think = SUB_Remove;
  357.     death.owner = death_owner;
  358.     
  359.     force_retouch = 2;              // make sure even still objects get hit
  360. };
  361.  
  362. void() teleport_touch = {
  363. local entity    t;
  364. local vector    org;
  365.  
  366.     if (self.targetname)
  367.     {
  368.         if (self.nextthink < time)
  369.         {
  370.             return;         // not fired yet
  371.         }
  372.     }
  373.  
  374.     if (self.spawnflags & PLAYER_ONLY)
  375.     {
  376.         if (other.classname != "player")
  377.             return;
  378.     }
  379.  
  380. //Godel qc: changed to teleport weapons and items
  381.     if ((other.classname=="trigger_changelevel") |
  382.         (other.classname=="trap_shooter") |
  383.         (other.classname=="tripbomb") |
  384.         (other.classname=="trap_spikeshooter") |
  385.         (other.classname=="trigger_secret") |
  386.         (other.classname=="trigger_hurt") |
  387.         (other.classname=="door") |
  388.         (other.classname=="explo_box") |
  389.         (other.classname=="bubble") |
  390.         (other.classname=="path_corner") |
  391.         (other.classname=="plat") |
  392.         (other.classname=="train") |
  393.         (other.classname=="teledeath") |
  394.         (other.classname=="teledeath2") |
  395.         (other.classname=="DelayedUse") |
  396.         (other.classname=="info_player_start") |
  397.         (other.classname=="testplayerstart") |
  398.         (other.classname=="info_player_coop") |
  399.         (other.classname=="info_intermission") |
  400.         (other.classname=="info_player_deathmatch") |
  401.         (other.classname=="misc_teleporttrain") )
  402.     {
  403.     return;
  404.     }
  405.  
  406.     SUB_UseTargets ();
  407.  
  408. // put a tfog where the player was
  409.     spawn_tfog (other.origin);
  410.  
  411.     t = find (world, targetname, self.target);
  412.     if (!t)
  413.         objerror ("couldn't find target");
  414.         
  415. // spawn a tfog flash in front of the destination
  416.     makevectors (t.mangle);
  417.     org = t.origin + 32 * v_forward;
  418.  
  419.     spawn_tfog (org);
  420.     spawn_tdeath(t.origin, other);
  421.  
  422. // move the player and lock him down for a little while
  423.     if (!other.health)
  424.     {
  425.         other.origin=t.origin;
  426.         other.velocity = (v_forward * vlen(other.velocity));
  427.         return;
  428.     }
  429.  
  430.     setorigin (other, t.origin);
  431.     other.angles = t.mangle;
  432.     if (other.classname == "player")
  433.     {
  434.         other.fixangle = 1;             // turn this way immediately
  435.         other.teleport_time = time + 0.7;
  436.         if (other.flags & FL_ONGROUND)
  437.             other.flags = other.flags - FL_ONGROUND;
  438.         other.velocity = v_forward * 300;
  439.     }
  440.     other.flags = other.flags - other.flags & FL_ONGROUND;
  441. };
  442.  
  443. /*QUAKED info_teleport_destination (.5 .5 .5) (-8 -8 -8) (8 8 32)
  444. This is the destination marker for a teleporter.  It should have a "targetname" field with the same value as a teleporter's "target" field.
  445. */
  446. void() info_teleport_destination =
  447. {
  448. // this does nothing, just serves as a target spot
  449.     self.mangle = self.angles;
  450.     self.angles = '0 0 0';
  451.     self.model = "";
  452.     self.origin = self.origin + '0 0 27';
  453.     if (!self.targetname)
  454.         objerror ("no targetname");
  455. };
  456.  
  457. void() teleport_use =
  458. {
  459.     self.nextthink = time + 0.2;
  460.     force_retouch = 2;              // make sure even still objects get hit
  461.     self.think = SUB_Null;
  462. };
  463.  
  464. /*QUAKED trigger_teleport (.5 .5 .5) ? PLAYER_ONLY SILENT
  465. Any object touching this will be transported to the corresponding info_teleport_destination entity. You must set the "target" field, and create an object with a "targetname" field that matches.
  466.  
  467. If the trigger_teleport has a targetname, it will only teleport entities when it has been fired.
  468. */
  469. void() trigger_teleport =
  470. {
  471.     local vector o;
  472.  
  473.     InitTrigger ();
  474.     self.touch = teleport_touch;
  475.     // find the destination 
  476.     if (!self.target)
  477.         objerror ("no target");
  478.     self.use = teleport_use;
  479.  
  480.     if (!(self.spawnflags & SILENT))
  481.     {
  482.         precache_sound ("ambience/hum1.wav");
  483.         o = (self.mins + self.maxs)*0.5;
  484.         ambientsound (o, "ambience/hum1.wav",0.5 , ATTN_STATIC);
  485.     }
  486. };
  487.  
  488. /*
  489. ==============================================================================
  490.  
  491. trigger_setskill
  492.  
  493. ==============================================================================
  494. */
  495.  
  496. void() trigger_skill_touch =
  497. {
  498.     if (other.classname != "player")
  499.         return;
  500.         
  501.     cvar_set ("skill", self.message);
  502. };
  503.  
  504. /*QUAKED trigger_setskill (.5 .5 .5) ?
  505. sets skill level to the value of "message".
  506. Only used on start map.
  507. */
  508. void() trigger_setskill =
  509. {
  510.     InitTrigger ();
  511.     self.touch = trigger_skill_touch;
  512. };
  513.  
  514.  
  515. /*
  516. ==============================================================================
  517.  
  518. ONLY REGISTERED TRIGGERS
  519.  
  520. ==============================================================================
  521. */
  522.  
  523. void() trigger_onlyregistered_touch =
  524. {
  525.     if (other.classname != "player")
  526.         return;
  527.     if (self.attack_finished > time)
  528.         return;
  529.  
  530.     self.attack_finished = time + 2;
  531.     if (cvar("registered"))
  532.     {
  533.         self.message = "";
  534.         SUB_UseTargets ();
  535.         remove (self);
  536.     }
  537.     else
  538.     {
  539.         if (self.message != "")
  540.         {
  541.             centerprint (other, self.message);
  542.             sound (other, CHAN_BODY, "misc/talk.wav", 1, ATTN_NORM);
  543.         }
  544.     }
  545. };
  546.  
  547. /*QUAKED trigger_onlyregistered (.5 .5 .5) ?
  548. Only fires if playing the registered version, otherwise prints the message
  549. */
  550. void() trigger_onlyregistered =
  551. {
  552.     precache_sound ("misc/talk.wav");
  553.     InitTrigger ();
  554.     self.touch = trigger_onlyregistered_touch;
  555. };
  556.  
  557. //============================================================================
  558.  
  559. void() hurt_on =
  560. {
  561.     self.solid = SOLID_TRIGGER;
  562.     self.nextthink = -1;
  563. };
  564.  
  565. void() hurt_touch =
  566. {
  567.     if (other.takedamage)
  568.     {
  569.         self.solid = SOLID_NOT;
  570.         T_Damage (other, self, self, self.dmg);
  571.         self.think = hurt_on;
  572.         self.nextthink = time + 1;
  573.     }
  574.  
  575.     return;
  576. };
  577.  
  578. /*QUAKED trigger_hurt (.5 .5 .5) ?
  579. Any object touching this will be hurt
  580. set dmg to damage amount
  581. defalt dmg = 5
  582. */
  583. void() trigger_hurt =
  584. {
  585.     InitTrigger ();
  586.     self.touch = hurt_touch;
  587.     if (!self.dmg)
  588.         self.dmg = 5;
  589. };
  590.  
  591. //============================================================================
  592.  
  593. float PUSH_ONCE = 1;
  594.  
  595. void() trigger_push_touch =
  596. {
  597. //    Godel qc: make wind tunnels push all but spikes. This is by choice!
  598. //    else if (other.health > 0)
  599.     if ((other.classname!= "spike") && (other.classname!="tripbomb"))
  600.     {
  601.         other.velocity = self.speed * self.movedir * 10;
  602.         if (other.classname == "player")
  603.         {
  604.             if (other.fly_sound < time)
  605.             {
  606.                 other.fly_sound = time + 1.5;
  607.                 sound (other, CHAN_AUTO, "ambience/windfly.wav", 1, ATTN_NORM);
  608.             }
  609.         }
  610.     }
  611.     if (self.spawnflags & PUSH_ONCE)
  612.         remove(self);
  613. };
  614.  
  615.  
  616. /*QUAKED trigger_push (.5 .5 .5) ? PUSH_ONCE
  617. Pushes the player
  618. */
  619. void() trigger_push =
  620. {
  621.     InitTrigger ();
  622.     precache_sound ("ambience/windfly.wav");
  623.     self.touch = trigger_push_touch;
  624.     if (!self.speed)
  625.         self.speed = 1000;
  626. };
  627.  
  628. //============================================================================
  629.  
  630. void() trigger_monsterjump_touch =
  631. {
  632.     if ( other.flags & (FL_MONSTER | FL_FLY | FL_SWIM) != FL_MONSTER )
  633.         return;
  634.  
  635. // set XY even if not on ground, so the jump will clear lips
  636.     other.velocity_x = self.movedir_x * self.speed;
  637.     other.velocity_y = self.movedir_y * self.speed;
  638.     
  639.     if ( !(other.flags & FL_ONGROUND) )
  640.         return;
  641.     
  642.     other.flags = other.flags - FL_ONGROUND;
  643.  
  644.     other.velocity_z = self.height;
  645. };
  646.  
  647. /*QUAKED trigger_monsterjump (.5 .5 .5) ?
  648. Walking monsters that touch this will jump in the direction of the trigger's angle
  649. "speed" default to 200, the speed thrown forward
  650. "height" default to 200, the speed thrown upwards
  651. */
  652. void() trigger_monsterjump =
  653. {
  654.     if (!self.speed)
  655.         self.speed = 200;
  656.     if (!self.height)
  657.         self.height = 200;
  658.     if (self.angles == '0 0 0')
  659.         self.angles = '0 360 0';
  660.     InitTrigger ();
  661.     self.touch = trigger_monsterjump_touch;
  662. };
  663.  
  664.